﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing.Design;
using ThreeByte.ActiveDeck.Config;
using ThreeByte.ActiveDeck.Controls;
using System.Windows.Forms.Design;
using System.Windows.Forms;
using ThreeByte.ActiveDeck.AddIn.Content.Controls;

namespace ThreeByte.ActiveDeck.AddIn.Config.Properties
{
    public class ActionEditor : UITypeEditor
    {
        public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context) {
            return UITypeEditorEditStyle.Modal;
        }

        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value) {
            //Open an Action Dialog here
            CoreConfig currentConfig = Globals.ThisAddIn.GetCurrentConfig();
            ActionSetupControl actionControl = new ActionSetupControl(currentConfig, value as NavigationAction);
            HostForm newDialog = new HostForm(actionControl);

            if(provider != null) {
                IWindowsFormsEditorService editorService = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;

                if(editorService != null) {
                   DialogResult result = editorService.ShowDialog(newDialog);
                   if(result == DialogResult.OK) {
                       return actionControl.ConfiguredAction;
                   }
                }
            }
           

            return value;
        }
    }
}
